<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">

      <el-form-item label="车牌号" prop="carNo">
        <el-input
          v-model="queryParams.carNo"
          placeholder="请输入车牌号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="称重时间">
      <el-date-picker
        v-model="dateRange"
        size="small"
        style="width: 240px"
        value-format="yyyy-MM-dd"
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      ></el-date-picker>
    </el-form-item>
      <el-form-item label="所属场站" prop="stationName">
        <el-input
          v-model="queryParams.stationName"
          placeholder="请输入所属场站"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="驾驶员" prop="driverName">
        <el-input
          v-model="queryParams.driverName"
          placeholder="请输入驾驶员姓名或联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['data:waybill:export']"
        >导出</el-button>
      </el-col>
    </el-row>-->

    <el-table v-loading="loading" :data="czycList" :max-height="tableHeight" @selection-change="handleSelectionChange">
      <el-table-column label="场站名称" align="left" prop="stationName" width="300"/>
      <el-table-column label="车牌号" align="center" prop="plantNo" />
      <el-table-column label="挂车车牌" align="center" prop="plantNoG" />
      <el-table-column label="称重总重(单位kg)" align="center" prop="recordWeight" />
      <el-table-column label="总质量(核定)" align="center" prop="czWeight" />
      <el-table-column label="轴数(标准)" align="center" prop="axle" />
<!--      <el-table-column label="是否超重(场站判定)" align="center" prop="isOverWeight"  :formatter="isOverWeightFormat" />-->
<!--      <el-table-column label="平台判定" align="center" prop="isCzyc" :formatter="isCzycFormat" />-->
      <el-table-column label="判定说明" align="left" prop="czdesc" width="160"/>
      <el-table-column label="称重时间" align="center" prop="weightTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.weightTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.waybillId != '' && scope.row.waybillId != undefined"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleYunView(scope.row)"
          >运单详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >称重详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
  import { listGetCzYcData,listGetCzYcData2 } from "@/api/weight/abnormal";

  export default {
    name: "czabnormal",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 称重异常
        czycList: [],
        // 认证状态
        dict_waybill_status: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        tableHeight: window.innerHeight - 275,
        //日期范围
        dateRange: [],
        dict_isOverWeight: [{'dictLabel':'是','dictValue':1},{'dictLabel':'否','dictValue':0}],
        dict_isCzyc: [{'dictLabel':'是','dictValue':1},{'dictLabel':'否','dictValue':0},{'dictLabel':'未判定','dictValue':2}],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          waybillNum: undefined,
          stationName: undefined,
          carNo: undefined,
          isAbnormal: undefined
        },
        // 表单参数
        form: {}
      };
    },
    created() {
      this.getList();
      // 认证状态
      this.getDicts("waybill_status").then(response => {
        this.dict_waybill_status = response.data;
      });
    },
    methods: {
      /** 查询运单列表 */
      getList() {
        this.loading = true;
        listGetCzYcData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.czycList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          waybillId: undefined,
          waybillNum: undefined,
          stationName: undefined,
          carNo: undefined,
          driverName: undefined,
          isAbnormal: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 运单详情 */
      handleYunView(row) {
        this.reset();
        const waybillId = row.waybillId || this.ids
        this.$router.push({
          path:"/weigh/waybilldetail",
          query:{
            id:waybillId
          }
        })
      },
      /** 详情按钮操作 */
      handleView(row) {
        this.reset();
        const id = row.id
        this.$router.push({
          path:"/weigh/recorddetail",
          query:{
            id:id
          }
        })

        // getWaybill(waybillId).then(response => {
        //   this.form = response.data;
        //   this.open = true;
        //   this.title = "运单详情";
        // });
      },
      //table改变按钮
      handleSelectionChange(){

      },

      axleFormat(row,column) {
        console.log(row.axleSource)
        if (row.axleSource != "" && row.axleSource != undefined){
          return row.axleNum+"("+row.axleSource+")";
        }
        else if (row.axleSourceG != "" && row.axleSourceG != undefined){
          return row.axleNum+"("+row.axleSourceG+")";
        }
        else if (row.axleSource != "" && row.axleSource != undefined && row.axleSourceG != "" && row.axleSourceG != undefined){
          return row.axleNum+"(皆是)";
        }else {
          return row.axleNum;
        }

      },
      isOverWeightFormat(row,column) {
        return this.selectDictLabel(this.dict_isOverWeight, row.isOverWeight);
      },
      isCzycFormat(row,column){
        return this.selectDictLabel(this.dict_isCzyc, row.isCzyc);
      },

      /** 删除按钮操作 */
      handleDelete(row) {
        const id = row.waybillId;
        console.info(id)
        this.$confirm('是否确认删除运单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWaybill(id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有运单数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWaybill(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      }
    }
  };
</script>
